﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using Fusion;

namespace Fusion.Interface
{
	public class ButtonPicker : Control
	{
		List<ToggleButton> buttons = new List<ToggleButton>();
		int selection = 0;
		public int Selection
		{
			get { return selection; }
		}

		public ButtonPicker( VoidDelegate ChangeEvent )
		{
			Clicked += ChangeEvent;
		}

		public void Add( ToggleButton btn )
		{
			btn.container = this;
			buttons.Add( btn );
		}

		public void Select( int sel )
		{
			if( sel < 0 ) sel = 0;
			if( sel >= buttons.Count ) sel = buttons.Count - 1;

			selection = sel;
			foreach( ToggleButton btn in buttons )
				btn.isChecked = false;
			buttons[selection].isChecked = true;
		}

		public override void Input( Vector2 cursor, bool button )
		{
			for( int i=0; i<buttons.Count; i++ )
			{
				buttons[i].Input( cursor, button );
				if( buttons[i].clicked == true )
				{
					selection = i;
					if( Clicked != null ) Clicked();
				}
			}
		}

		public override void Update()
		{
			foreach( ToggleButton btn in buttons )
				btn.Update();

			foreach( ToggleButton btn in buttons )
				btn.isChecked = false;
			buttons[selection].isChecked = true;
		}

		public override void Draw()
		{
			if( hidden == true )
				return;

			foreach( ToggleButton btn in buttons )
				btn.Draw();
		}
	}
}
